package edu.pet.Servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import edu.pet.DAO.PetDAO;
import edu.pet.entity.History;
import edu.pet.entity.Pet;

public class HistoryViewServlet extends HttpServlet {

	public HistoryViewServlet() {
		super();
	}

	public void destroy() {
		super.destroy(); 
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		int petid = Integer.parseInt(request.getParameter("petid"));
		
		PetDAO petDao = new PetDAO();
		
		ArrayList<History> historyList = petDao.queryHistory(petid);
		petDao = new PetDAO();
		Pet pet = petDao.searchPet(petid);
		
		request.setAttribute("pet", pet);
		HttpSession session = request.getSession();
		session.setAttribute("historyList", historyList);

		response.sendRedirect("../user/history.jsp");
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doGet(request, response);
	}

	public void init() throws ServletException {
		
	}

}
